package com.yn.xgame.logic.util;

import java.util.Calendar;
import java.util.Random;

import com.yn.xgame.logic.common.SysConst;

public class GenUtils {
	
	/**
	 * 生成玩家token
	 * @param username
	 * @return
	 */
	public static String genUserToken(String username){
		Calendar cal=Calendar.getInstance();
		String timeFiled=cal.get(Calendar.DATE)+"/"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.YEAR);
		String input=username+timeFiled+SysConst.TOKEN_KEY;
		String token=MD5Utils.encryptTohex(input);
		return token;
	}
	
	/**
	 * 生成验证码
	 * @return
	 */
	public static String genCaptcha(){
		String captcha="";
		Random random=new Random();
		for(int i=0;i<4;i++){
			captcha+=random.nextInt(10);
		}
		return captcha;
	}
}
